<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>书城首页</title>
		<link type="text/css" rel="stylesheet" href="/static/css/style.css">
		<script src="/static/script/jquery.js"></script>
		<script>
			$(function () {
				$(".addCart").click(function () {
					var bookID = $(this).attr("id");
					var url = "/addCart"
					var param = { "bookID": bookID }
					$.post(url, param, function (res) {
						if (res == "请先登录！") {
							location = "/pages/user/login.html"
						} else {
							$("#bookMsg").text(res)
						}
					});
				});
			});
		</script>
	</head>

	<body>

		<div id="header">
			<span class="wel_word">网上书城</span>
			{{ if .IsLogin }}
			<div>
				<span>欢迎<span class="um_span">{{.Username }}</span>光临书城</span>
				<a href="/logout">注销</a>&nbsp;&nbsp;
				<a href="/cart">购物车</a>
				<a href="/queryMyOrderHandler">我的订单</a>
				<a href="/">返回</a>
			</div>
			{{ else}}
			<div>
				<a href="pages/user/login.html">登录</a> |
				<a href="pages/user/regist.html">注册</a> &nbsp;&nbsp;
				<a href="/pages/user/rootLogin.html">后台管理</a>
			</div>
			{{ end }}
		</div>

		<div id="main">
			<div id="book">
				<form action="/search" method="POST">
					<br />
					<div style="text-align: center;">
						<input type="text" name="search"><button>搜索</button>
					</div>
					<br />
				</form>

				<div style="text-align: center">
					<div>
						<span style="color: red" id="bookMsg"></span></span>
					</div>
				</div>

				{{ range .Books }}
				<div class="b_list">
					<div class="img_div">
						<img class="book_img" alt="" src={{.ImgPath }} />
					</div>
					<div class="book_info">
						<div class="book_name">
							<span class="sp1">书名:</span>
							<span class="sp2">{{.Title }}</span>
						</div>
						<div class="book_author">
							<span class="sp1">作者:</span>
							<span class="sp2">{{.Author }}</span>
						</div>
						<div class="book_price">
							<span class="sp1">价格:</span>
							<span class="sp2">￥{{.Price }}</span>
						</div>
						<div class="book_sales">
							<span class="sp1">销量:</span>
							<span class="sp2">{{.Sales }}</span>
						</div>
						<div class="book_amount">
							<span class="sp1">库存:</span>
							<span class="sp2">{{.Stock }}</span>
						</div>
						<div class="book_add">
							{{ if .Stock }}
							<button id="{{.ID}}" class="addCart">加入购物车</button>
							{{ else}}
							<span style="color:red">小二拼命补货中...</span>
							{{ end }}

						</div>
					</div>
				</div>
				{{ end }}
			</div>

			<div id="page_nav">
				{{ if .IsHasPrev }}
				<a href="/">首页</a>
				<a href="/?pageNum={{.GetPrevPageNum}}">上一页</a>
				{{ end }}

				当前是第{{.PageNum }}页共{{.TotalPageNum }}页，{{.TotalRecurd }}条记录
				{{ if .IsHasNext }}
				<a href="/?pageNum={{.GetNextPageNum}}">下一页</a>
				<a href="/?pageNum={{.TotalPageNum}}">末页</a>
				{{ end }}
				到第<input value="{{.PageNum}}" name="pn" id="pn_input" />页
				<input type="button" value="确定" id="sub">
				<script>
					$("#sub").click(function () {
						var pageNum = $("#pn_input").val();
						location = "/?pageNum=" + pageNum
					});
				</script>
			</div>

		</div>

		<div id="bottom">
			<span>
				书城.Copyright &copy;2020.<a href="http://www.beian.miit.gov.cn/">鄂ICP备20002228号</a>
			</span>
		</div>
	</body>

</html>